home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / plugins / subunit_report.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  2.2 KB  |  76 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import logging
  20.  
  21. from checkbox.test import FAIL, PASS, SKIP
  22.  
  23. from checkbox.properties import Path
  24. from checkbox.plugin import Plugin
  25.  
  26.  
  27. class SubunitReport(Plugin):
  28.  
  29.     # Filename where to store the subunit report
  30.     filename = Path(default="%(checkbox_data)s/subunit.log")
  31.  
  32.     result_status_table = {
  33.         FAIL: "failure",
  34.         PASS: "success",
  35.         SKIP: "skip"}
  36.  
  37.     def register(self, manager):
  38.         super(SubunitReport, self).register(manager)
  39.         self._file = None
  40.  
  41.         for (rt, rh) in [
  42.              ("gather", self.gather),
  43.              ("report-result", self.report_result)]:
  44.             self._manager.reactor.call_on(rt, rh)
  45.  
  46.     def gather(self):
  47.         logging.debug("Opening filename: %s", self.filename)
  48.         self._file = open(self.filename, "w")
  49.  
  50.     def report_result(self, result):
  51.         # Test
  52.         test = result.test
  53.         name = "%s %s" % (test.suite, test.name)
  54.         self._file.write("test: %s\n" % name)
  55.  
  56.         # Tags
  57.         tags = []
  58.         if result.packages:
  59.             tags.extend(["package:%s-%s" % (p.name, p.version)
  60.                 for p in result.packages])
  61.         if tags:
  62.             self._file.write("tags: %s\n" % " ".join(tags))
  63.  
  64.         # Status
  65.         status = self.result_status_table[result.status]
  66.         self._file.write("%s: %s" % (status, name))
  67.         if result.data:
  68.             # Prepend whitespace to the data
  69.             data = result.data.replace("\n", "\n ").strip()
  70.             self._file.write(" [\n %s\n]\n" % data)
  71.         else:
  72.             self._file.write("\n")
  73.  
  74.  
  75. factory = SubunitReport
  76.